package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TAccountInfo;
import com.ruoyi.business.service.ITAccountInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户账户Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@Controller
@RequestMapping("/business/accountInfo")
public class TAccountInfoController extends BaseController
{
    private String prefix = "business/accountInfo";

    @Autowired
    private ITAccountInfoService tAccountInfoService;

    @RequiresPermissions("business:accountInfo:view")
    @GetMapping()
    public String accountInfo(ModelMap mmap)
    {
        mmap.put("sysUser", new SysUser());
        return prefix + "/accountInfo";
    }

    /**
     * 查询商户账户列表
     */
    @RequiresPermissions("business:accountInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TAccountInfo tAccountInfo)
    {
        startPage();
        List<TAccountInfo> list = tAccountInfoService.selectTAccountInfoList(tAccountInfo);
        return getDataTable(list);
    }

    /**
     * 导出商户账户列表
     */
    @RequiresPermissions("business:accountInfo:export")
    @Log(title = "商户账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TAccountInfo tAccountInfo)
    {
        List<TAccountInfo> list = tAccountInfoService.selectTAccountInfoList(tAccountInfo);
        ExcelUtil<TAccountInfo> util = new ExcelUtil<TAccountInfo>(TAccountInfo.class);
        return util.exportExcel(list, "商户账户数据");
    }

    /**
     * 新增商户账户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户账户
     */
    @RequiresPermissions("business:accountInfo:add")
    @Log(title = "商户账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TAccountInfo tAccountInfo)
    {
        return toAjax(tAccountInfoService.insertTAccountInfo(tAccountInfo));
    }

    /**
     * 修改商户账户
     */
    @RequiresPermissions("business:accountInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TAccountInfo tAccountInfo = tAccountInfoService.selectTAccountInfoById(id);
        mmap.put("tAccountInfo", tAccountInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户账户
     */
    @RequiresPermissions("business:accountInfo:edit")
    @Log(title = "商户账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAccountInfo tAccountInfo)
    {
        return toAjax(tAccountInfoService.updateTAccountInfo(tAccountInfo));
    }

    /**
     * 删除商户账户
     */
    @RequiresPermissions("business:accountInfo:remove")
    @Log(title = "商户账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tAccountInfoService.deleteTAccountInfoByIds(ids));
    }

    @RequiresPermissions("business:accountInfo:edit")
    @ResponseBody
    @PostMapping("/recharge")
    @Log(title = "商户账户充值", businessType = BusinessType.RECHARGE)

    public AjaxResult recharge( TAccountInfo accountInfoParam) {
        tAccountInfoService.recharge(accountInfoParam);
        return AjaxResult.success();
    }

}
